package com.fs.procure.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.core.vo.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.util.page.PageUtils;
import com.fs.procure.pojo.Rta;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.procure.service.IRtaService;

/**
 * 退货申请Controller
 * 
 * @author lan
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/procure/rta")
public class RtaController extends BaseController
{
    @Autowired
    private IRtaService rtaService;

    /**
     * 查询退货申请列表
     */
    @PreAuthorize("@ss.hasPermi('procure:rta:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rta rta)
    {
        PageUtils.startPage();
        List<Rta> list = rtaService.selectRtaList(rta);
        Page<Rta> page=new Page<>();
        page.setRecords(list);
        page.setTotal(list.size());
        return getDataTable(page);
    }

//    /**
//     * 导出退货申请列表
//     */
//    @PreAuthorize("@ss.hasPermi('procure:rta:export')")
//    @Log(title = "退货申请", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Rta rta)
//    {
//        List<Rta> list = rtaService.selectRtaList(rta);
//    }

    /**
     * 获取退货申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('procure:rta:query')")
    @GetMapping(value = "/{rtaId}")
    public AjaxResult getInfo(@PathVariable("rtaId") Long rtaId)
    {
        Rta rta = rtaService.selectRtaByRtaId(rtaId);
        return rta!=null?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 新增退货申请
     */
    @PreAuthorize("@ss.hasPermi('procure:rta:add')")
    @Log(title = "退货申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rta rta)
    {
        int i = rtaService.insertRta(rta);
        return i>0?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 修改退货申请
     */
    @PreAuthorize("@ss.hasPermi('procure:rta:edit')")
    @Log(title = "退货申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rta rta)
    {
        int i = rtaService.updateRta(rta);
        return i>0?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 删除退货申请
     */
    @PreAuthorize("@ss.hasPermi('procure:rta:remove')")
    @Log(title = "退货申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rtaIds}")
    public AjaxResult remove(@PathVariable Long[] rtaIds)
    {
        int i = rtaService.deleteRtaByRtaIds(rtaIds);
        return i>0?AjaxResult.success():AjaxResult.error();
    }
}
